#![allow(dead_code)]
extern crate rand;
use rand::{distributions::uniform::SampleUniform, prelude::*};

/// 返回num指定数量的随机数组
pub fn random_array<T: SampleUniform>(num: usize, range: std::ops::Range<T>) -> Vec<T>
where
    Vec<T>: FromIterator<T>,
{
    let rng = thread_rng();
    let distr = rand::distributions::Uniform::new_inclusive(range.start, range.end);
    rng.sample_iter(distr).take(num).collect()
}

/// 返回range指定范围的一个随机数
pub fn random_num<T: SampleUniform + Ord + Default>(range: std::ops::Range<T>) -> T {
    if range.is_empty() {
        return T::default();
    }
    let mut rng = thread_rng();
    rng.gen_range(range)
}
